<template>
  <div class="exportXlsx">
      <!-- 导出   直接调-->
    <el-button type="success" plain @click="exportXlsx" size="mini">导出Excel</el-button>
  </div>
</template>

<script>
import {
    exprotXls,//导出xlsx数据
  } from "@/api/waterMeterInfo/flMachineMeterInfo/index";
export default {

    name:'exportXlsx',
    data (){
        return{}
    },
    methods:{
        // async exportXlsx() {
        //     const res = await exprotXls()
        //     console.log(res,'结果是');

        // },
      // 导出方法
      async exportXlsx() {
        console.log('导出Xlsx',this.$parent.exprotXlsx,777);
        try {
          const { exprotXlsx } = this.$parent
          // console.log(exprotXlsx);
          const res = await exprotXlsx()
          // let iconv = require('iconv-lite');
          // iconv.skipDecodeWarning = true;//忽略警告
          // let fileName = iconv.decode(res.filename, 'utf-8');
          // let fenge =fileName.split(';')[1]
          // fileName = fenge.split('=')[1]
          console.log(res,'导出结果');
          let fileName = decodeURI(
            res["filename"].split("=")[1]
          );
          // let blob = new Blob([res], {type: "application/vnd.ms-excel"});
          let blob = new Blob([res], {type: "application/vnd.ms-excel;charset=utf-8"});
          var downloadA = document.createElement('a')
          downloadA.download = fileName
          downloadA.style.display = 'none'
          downloadA.href=URL.createObjectURL(blob)
          document.body.appendChild(downloadA)
          downloadA.click()
          URL.revokeObjectURL(downloadA.href)
          document.body.removeChild(downloadA)
          // 提示
          this.$notify({
              title: '导出成功',
              message: fileName,
              type: 'success'
          });
        } catch (error) {
          console.log(error);
          this.$notify.error({
              title: "错误",
              message: "下载失败！"
          });
        }
      },
    }

}
</script>

<style>

</style>
